using System;
using SharpObjects.Cryptography;
using SharpObjects.Cryptography.Hash;
using SharpObjects.Cryptography.Symmetric;

namespace SharpCryptography
{
	class Test
	{
		[STAThread]
		static void Main(string[] args)
		{
			Password();
			Crypto(args);
		}

		protected static string m_sStoredPasswordHash = new PasswordHash("mypassword");

		static void Password()
		{
			PasswordHash pwd;

			do
			{
				Console.Write("Enter password: ");
				string sInput = Console.ReadLine();
				pwd = new PasswordHash(sInput);
			}
			while(pwd != m_sStoredPasswordHash);

		}

		static void Crypto(string [] args)
		{
			ICryptoProvider provider;
			KeyFile kf;

			if(args.Length > 0 && args[0] == "create_key")
			{
				provider = new RijndaelProvider();
				kf = new KeyFile("..\\..\\key", provider);
				kf.Save();
				return;
			}

			string sText = "This is my text";

			provider = new RijndaelProvider();
			kf = new KeyFile("..\\..\\key", provider);
			kf.Load();

			Console.WriteLine("Original text:  " + sText);
			Cryptographer crypt = new Cryptographer(provider);
			string sEncrypted = crypt.EncryptToBase64Text(sText);
			Console.WriteLine("Encrypted (base 64): " + sEncrypted);
			string sDecrypted = crypt.DecryptToUtf8Text(sEncrypted);
			Console.WriteLine("Decrypted text: " + sDecrypted);

		}
	}
}
